<!DOCTYPE html>
<html lang="en"><!-- InstanceBegin template="/Templates/MainTemplate.dwt" codeOutsideHTMLIsLocked="false" -->
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="description" content="">
    <meta name="author" content="">
<!-- #BeginEditable "doctitle" -->
<title>CES:Context Event and State</title>  
<!-- #EndEditable -->
<!-- InstanceBeginEditable name="head" --><!-- InstanceEndEditable -->
    <!-- Bootstrap core CSS -->
     <link rel="stylesheet" href="css/bootstrap.min.css">   

    <!-- Custom styles for this template -->
    <link href="css/starter-template.css" rel="stylesheet">

   <!-- HTML5 shim and Respond.js IE8 support of HTML5 elements and media queries -->
    <!--[if lt IE 9]>
      <script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
      <script src="https://oss.maxcdn.com/libs/respond.js/1.3.0/respond.min.js"></script>
    <![endif]-->    
  </head>
<body>
 <div class="navbar navbar-inverse navbar-fixed-top" role="navigation">
      <div class="container">
        <div class="navbar-header">
          <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
            <span class="sr-only">Toggle navigation</span>
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
          </button>
          <a class="navbar-brand" href="index.html">Jdon Framework</a>
        </div>
        <div class="collapse navbar-collapse">
          <ul class="nav navbar-nav">
                <li class="active"><a href="index.html">Home</a></li>
               <li><a href="https://sourceforge.net/projects/jdon/files/">Download</a></li>
               <li><a href="doc.htm" >Document</a></li>
               <li><a href="quickconf.html">Qucik Start</a> </li>
               <li><a href="examples.html">Examples</a></li>
               <li ><a href="https://github.com/banq/jdonframework">Github</a></li>
               <li><a href="articles.html">Articles</a></li>
          </ul>
        </div><!--/.nav-collapse -->
      </div>
    </div>
    

    <div class="container">
     <div class="starter-template">     
    
 <table width="100%" border="0" cellspacing="0" cellpadding="0" align="center">  
  <tr>     
    <td bgcolor="#FFFFFF"  valign="top" align="left">

                  
				<!-- #BeginEditable "main" --> 
                  <h1>CES:Context Event and State</h1>
                  <p>　　How to translate business logic into a ubiouitous language? what kind of ubiouitous language can combine OO and FP(Funtcion programming)?</p>
                  <p>　　the answer is here:</p>
                  <p>　　<img src="images/ces.png" width="630" height="357" alt="ces"></p>
                  <p>　　The route from Domain  to aggregation  Entity belongs to DDD(Domain-driven design), it is a structural perspective view, this is strengths of OO, the entity hold the business logic running state that will be written into database. later we can query and analysis these data results in <a href="http://martinfowler.com/bliki/CQRS.html">CQRS</a> system.</p>
                  <p>　　Another route is from Context to Event and State, this perspective view is from FP(function programming), in a context, there will be happen a event that will modify the state of a entity. it is like <a href="http://en.wikipedia.org/wiki/Data,_context_and_interaction">DCI</a>(Data Context and Interaction).</p>
                  <p><strong>Event:DBC</strong></p>
                  <p>　　In this  ubiouitous language, we inroduce Event pattern that service  for business logic, it is not architecture events such as a Window Event or click event.</p>
                  <p>　　Event is a contact of <a href="http://en.wikipedia.org/wiki/Design_by_contract">Design By Contact</a>(DBC) that include <a href="http://en.wikipedia.org/wiki/Precondition" title="Precondition">                  Preconditions</a> <a href="http://en.wikipedia.org/wiki/Postcondition" title="Postcondition">Postconditions</a> and <a href="http://en.wikipedia.org/wiki/Invariant_(computer_science)" title="Invariant (computer science)">Invariants</a>. in a context that happened a event, we can divide into :before event(Precondition) after event(Postconditions) and event happened result(state: invariants). the state is a value object of aggregation root entity, see <a href="Immutability.html">Immutability is everything</a> .</p>
                  <p>　　Example:As a customer,
                    I want to withdraw cash from an ATM,
                  so that I don’t have to wait in line at the bank.</p>
                  <p id="body_23139532">　　</p>
                  <table width="600" border="0">
                    <tr>
                      <td bgcolor="#CCCCCC"><p>[Precondition/before event]<br>
                        Given the account is in credit<br>
　　And the card is valid <br>
　　And the dispenser contains cash </p>
<p>When &quot;the customer requests cash &quot; <strong>event</strong> happened</p>
                        <p>[Postconditions/after event]<br>
                          Then ensure the account is debited (account state is modified)<br>
                          　　And ensure cash is dispensed <br>
                          　　And ensure the card is returned </p>
                        <p></p></td>
                    </tr>
                  </table>
                  <p>&nbsp;</p>
<p><strong>Context</strong></p>
<p>　　Context is about all business entity interactions, in a context, a entity of aggregation root act as a role triggers all domain event with other aggregations. in a aggregation,  a method directly invoke other methods in synchronous mode, but betwwen aggregations a event happens in asynchronous or concurrent mode.</p>
<p>　　in here the Conext maybe  equivalent to bouned context in DDD, or equivalent to context of DCI, so, we can combine DDD(OO) and DCI(FP) into a system. but we must clearly know what differences between them, Context is a bridge of them.</p>
<p>　　In CQRS and Event Sourcing, user send a command into system, and the command handler will transfer the event to a Service or a Aggregation root. aggregation root will   in a context response  for the event from front end. this is a paradigm that OO commands FP.</p>
<p>　　summary: CES uses FP paradigm patching up OO paradigm, and makes DDD practice more closer to user story or features list, brings DDD with <a href="http://en.wikipedia.org/wiki/Behavior-driven_development">BDD</a>  onto a agile way. CES can be   implemented in traditional OO language such as Java or C#, that will be better in FP langugae.</p>
　　Service/Message model has gone, next big thing is Context/Event model.
<p><a href="https://github.com/banq/jdonframework/tree/master/example">JdonFramework DDD + CQRS + EventSourcing examples </a></p>
<p><a href="match.html">DDD CQRS EventSourcing example source: football Match</a></p>
<p>related articles:</p>
<p><a href="http://www.infoq.com/presentations/CAP-DDD" target="_blank" onMouseDown="return rwt(this,'','','','1','AFQjCNFlhttddxYBmff4ijj2n-SfPXGUxw','','0CCwQFjAA','','',event)"><em>Eric evans: Acknowledging CAP at the Root -- in the Domain Model</em></a></p>
<p><strong><a href="http://www.eventuallyinconsistent.com/2012/12/speaking-experience.html" target="_blank">Changing the mindset - more object-oriented view at the business domain modeling</a></strong></p>
<p><a href="http://www.slideshare.net/chris.e.richardson/decomposing-applications-for-deployability-and-scalability-springone2gx-s12gx?ref=https://twitter.com/">Decomposing applications for deployability and scalabilit</a></p>
<p><a href="http://blog.aggregateknowledge.com/2012/10/18/adventures-in-concurrency/">Adventures in Concurrency</a></p>
<p><a href="https://github.com/eligosource/eventsourced-example">Scala Event-Sourced</a> </p>
<p><strong><a href="DomainEvents.html">DDD</a></strong> <a href="DomainEvents.html"><strong>DCI</strong> and <strong>Domain</strong> <strong>Events</strong> <strong>example</strong></a></p>
<p><a href="dci.html">how to enhance Jdon framework to DCI framework ?</a></p>
<p><a href="Immutability.html">Immutability is everything</a></p>
<p><a href="non-blocking.html">how to easily develop a non-blocking concurrent application ?</a></p>
<p>&nbsp;</p>
                  <p>&nbsp;</p>
                   <!-- #EndEditable -->
                 
			  	
          </td>
		  <td width="340" valign="top"  bgcolor="#FFFFD7"> 
          <div class="adsensf" id="vgad336x280">
<script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<!-- 页上左336 -->
<ins class="adsbygoogle"
     style="display:inline-block;width:336px;height:280px"
     data-ad-client="ca-pub-7573657117119544"
     data-ad-slot="6751585519"></ins>
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script>
<script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<!-- 页上左336 -->
<ins class="adsbygoogle"
     style="display:inline-block;width:336px;height:280px"
     data-ad-client="ca-pub-7573657117119544"
     data-ad-slot="6751585519"></ins>
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script>
</div>         
 </td>
  </tr>
</table>


<table width="100%" border="0" cellspacing="0" cellpadding="0" height="2" bgcolor="#000000"  align="center">
              <tr>
                <td></td>
              </tr>
</table>
<table width="100%" border="0" cellspacing="0" cellpadding="0" align="center">
<tr><td height="20" bgcolor="#CAC9BB" align="center">
  
  </td>
</tr>
</table>
 </div>
</div><!-- /.container -->

<!-- InstanceBeginEditable name="EditRegion3" --><!-- InstanceEndEditable -->
        <script src="https://code.jquery.com/jquery-1.10.2.min.js"></script>
		<script src="js/bootstrap.min.js"></script>
<!-- AddThis Smart Layers BEGIN -->
<!-- Go to http://www.addthis.com/get/smart-layers to customize -->
<script type="text/javascript" src="//s7.addthis.com/js/300/addthis_widget.js#pubid=ra-52c4b79515624135"></script>
<script type="text/javascript">
  addthis.layers({
    'theme' : 'transparent',
    'share' : {
      'position' : 'left',
      'numPreferredServices' : 5
    },  
    'whatsnext' : {},  
    'recommended' : {} 
  });
</script>
<!-- AddThis Smart Layers END -->    
</body>
<!-- InstanceEnd --></html>
